﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class MemStorageTiming
    {
        private readonly Chain.IDAL.MemStorageTiming dal = new Chain.IDAL.MemStorageTiming();

        public int Add(Chain.Model.MemStorageTiming model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.MemStorageTiming> DataTableToList(DataTable dt)
        {
            List<Chain.Model.MemStorageTiming> list = new List<Chain.Model.MemStorageTiming>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.MemStorageTiming item = new Chain.Model.MemStorageTiming();
                    if ((dt.Rows[i]["StorageTimingID"] != null) && (dt.Rows[i]["StorageTimingID"].ToString() != ""))
                    {
                        item.StorageTimingID = int.Parse(dt.Rows[i]["StorageTimingID"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingMemID"] != null) && (dt.Rows[i]["StorageTimingMemID"].ToString() != ""))
                    {
                        item.StorageTimingMemID = int.Parse(dt.Rows[i]["StorageTimingMemID"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingAccount"] != null) && (dt.Rows[i]["StorageTimingAccount"].ToString() != ""))
                    {
                        item.StorageTimingAccount = dt.Rows[i]["StorageTimingAccount"].ToString();
                    }
                    if ((dt.Rows[i]["StorageTimingTotalMoney"] != null) && (dt.Rows[i]["StorageTimingTotalMoney"].ToString() != ""))
                    {
                        item.StorageTimingTotalMoney = decimal.Parse(dt.Rows[i]["StorageTimingTotalMoney"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingDiscountMoney"] != null) && (dt.Rows[i]["StorageTimingDiscountMoney"].ToString() != ""))
                    {
                        item.StorageTimingDiscountMoney = decimal.Parse(dt.Rows[i]["StorageTimingDiscountMoney"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingIsCard"] != null) && (dt.Rows[i]["StorageTimingIsCard"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["StorageTimingIsCard"].ToString() == "1") || (dt.Rows[i]["StorageTimingIsCard"].ToString().ToLower() == "true"))
                        {
                            item.StorageTimingIsCard = true;
                        }
                        else
                        {
                            item.StorageTimingIsCard = false;
                        }
                    }
                    if ((dt.Rows[i]["StorageTimingPayCard"] != null) && (dt.Rows[i]["StorageTimingPayCard"].ToString() != ""))
                    {
                        item.StorageTimingPayCard = decimal.Parse(dt.Rows[i]["StorageTimingPayCard"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingIsCash"] != null) && (dt.Rows[i]["StorageTimingIsCash"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["StorageTimingIsCash"].ToString() == "1") || (dt.Rows[i]["StorageTimingIsCash"].ToString().ToLower() == "true"))
                        {
                            item.StorageTimingIsCash = true;
                        }
                        else
                        {
                            item.StorageTimingIsCash = false;
                        }
                    }
                    if ((dt.Rows[i]["StorageTimingPayCash"] != null) && (dt.Rows[i]["StorageTimingPayCash"].ToString() != ""))
                    {
                        item.StorageTimingPayCash = decimal.Parse(dt.Rows[i]["StorageTimingPayCash"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingIsBink"] != null) && (dt.Rows[i]["StorageTimingIsBink"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["StorageTimingIsBink"].ToString() == "1") || (dt.Rows[i]["StorageTimingIsBink"].ToString().ToLower() == "true"))
                        {
                            item.StorageTimingIsBink = true;
                        }
                        else
                        {
                            item.StorageTimingIsBink = false;
                        }
                    }
                    if ((dt.Rows[i]["StorageTimingPayBink"] != null) && (dt.Rows[i]["StorageTimingPayBink"].ToString() != ""))
                    {
                        item.StorageTimingPayBink = decimal.Parse(dt.Rows[i]["StorageTimingPayBink"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingPayCoupon"] != null) && (dt.Rows[i]["StorageTimingPayCoupon"].ToString() != ""))
                    {
                        item.StorageTimingPayCoupon = decimal.Parse(dt.Rows[i]["StorageTimingPayCoupon"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingPayType"] != null) && (dt.Rows[i]["StorageTimingPayType"].ToString() != ""))
                    {
                        item.StorageTimingPayType = int.Parse(dt.Rows[i]["StorageTimingPayType"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingPoint"] != null) && (dt.Rows[i]["StorageTimingPoint"].ToString() != ""))
                    {
                        item.StorageTimingPoint = int.Parse(dt.Rows[i]["StorageTimingPoint"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingRemark"] != null) && (dt.Rows[i]["StorageTimingRemark"].ToString() != ""))
                    {
                        item.StorageTimingRemark = dt.Rows[i]["StorageTimingRemark"].ToString();
                    }
                    if ((dt.Rows[i]["StorageTimingShopID"] != null) && (dt.Rows[i]["StorageTimingShopID"].ToString() != ""))
                    {
                        item.StorageTimingShopID = int.Parse(dt.Rows[i]["StorageTimingShopID"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingUserID"] != null) && (dt.Rows[i]["StorageTimingUserID"].ToString() != ""))
                    {
                        item.StorageTimingUserID = int.Parse(dt.Rows[i]["StorageTimingUserID"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingCreateTime"] != null) && (dt.Rows[i]["StorageTimingCreateTime"].ToString() != ""))
                    {
                        item.StorageTimingCreateTime = DateTime.Parse(dt.Rows[i]["StorageTimingCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTotalTime"] != null) && (dt.Rows[i]["StorageTotalTime"].ToString() != ""))
                    {
                        item.StorageTotalTime = int.Parse(dt.Rows[i]["StorageTotalTime"].ToString());
                    }
                    if ((dt.Rows[i]["StorageResidueTime"] != null) && (dt.Rows[i]["StorageResidueTime"].ToString() != ""))
                    {
                        item.StorageResidueTime = int.Parse(dt.Rows[i]["StorageResidueTime"].ToString());
                    }
                    if ((dt.Rows[i]["StorageTimingProjectID"] != null) && (dt.Rows[i]["StorageTimingProjectID"].ToString() != ""))
                    {
                        item.StorageTimingProjectID = int.Parse(dt.Rows[i]["StorageTimingProjectID"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int StorageTimingID)
        {
            return this.dal.Delete(StorageTimingID);
        }

        public bool DeleteList(string StorageTimingIDlist)
        {
            return this.dal.DeleteList(StorageTimingIDlist);
        }

        public bool Exists(int StorageTimingID)
        {
            return this.dal.Exists(StorageTimingID);
        }

        public bool ExistsProject(int ProjectID)
        {
            return this.dal.ExistsProject(ProjectID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetAllTimeByMem(int memid, int projectid)
        {
            return this.dal.GetAllTimeByMem(memid, projectid);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public Chain.Model.MemStorageTiming GetModel(int StorageTimingID)
        {
            return this.dal.GetModel(StorageTimingID);
        }

        public List<Chain.Model.MemStorageTiming> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public DataSet GetTimeTotal(string strWhere)
        {
            return this.dal.GetTimeTotal(strWhere);
        }

        public bool Update(Chain.Model.MemStorageTiming model)
        {
            return this.dal.Update(model);
        }

        public bool UpdateStorageResidueTime(int StorageTimingID, int StorageResidueTime)
        {
            return this.dal.UpdateStorageResidueTime(StorageTimingID, StorageResidueTime);
        }
    }
}

